package com.ruoyi.vo.dahua;

/**
 * 返回MAS数据
 * @author 刘国徽(90466)
 */
public class DaHuaResponse<T> {

    public static final String SUCCESS_CODE = "0000";

    public static final String FAILED_CODE = "5000";

    private boolean success;

    private String code;

    private String errMsg;

    private T data;

    private Integer currentPage;

    private Integer totalRows;

    private Integer totalPage;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(Integer totalRows) {
        this.totalRows = totalRows;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public DaHuaResponse() {
    }

    public DaHuaResponse(boolean success, String code, String errMsg, T data) {
        this.success = success;
        this.code = code;
        this.errMsg = errMsg;
        this.data = data;
    }

    public void setDefaultCode() {
        if (this.success) {
            this.code = SUCCESS_CODE;
        } else {
            this.code = FAILED_CODE;
        }
    }

    // 静态工厂方法 - 用于分页数据
    public static <T> DaHuaResponse<T> successPage(T data, Integer currentPage, Integer totalRows, Integer totalPage) {
        DaHuaResponse<T> response = new DaHuaResponse<>();
        response.setSuccess(true);
        response.setCode(SUCCESS_CODE);
        response.setData(data);
        response.setCurrentPage(currentPage);
        response.setTotalRows(totalRows);
        response.setTotalPage(totalPage);
        return response;
    }

    // 静态工厂方法 - 用于非分页数据
    public static <T> DaHuaResponse<T> success(T data) {
        DaHuaResponse<T> response = new DaHuaResponse<>();
        response.setSuccess(true);
        response.setCode(SUCCESS_CODE);
        response.setData(data);
        return response;
    }
}
